package engine.display.newAttack.action
{
	import engine.display.newAttack.AttackLogic;
	import engine.display.newAttack.AttackPlayer;
	import engine.display.newAttack.action.effect.PointPlayLite;
	import engine.display.newAttack.vo.AttackActionVo;
	import engine.display.newAttack.vo.DamageVo;
	import engine.display.newAttack.vo.FlowVo;
	import engine.flag.PlayerActionFlag;
	import engine.logic.McPool;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	/**
	 *	多人近战物理 
	 * @author lw
	 * 
	 */
	public class ManyPhyCloseAttack extends PhyCloseAttack
	{
		private var _tPlayers : Array;
		public function ManyPhyCloseAttack(fPlayer:AttackPlayer, 
										   tPlayers:Array, 
										   flowVo : FlowVo, 
										   attackActionVo:AttackActionVo,
										   onPlay:Function, 
										   onPlayOver:Function=null, 
										   soundHit:String="")
		{
			super(fPlayer, tPlayers, flowVo, attackActionVo, onPlay, 
				onPlayOver, soundHit );
			
			_tPlayers = tPlayers;
		}
		
		override protected function onPlayAttack(e:Event):void
		{
			var	fromSkin:MovieClip	=	_fPlayer.getSkin();
			
			if(fromSkin == null)
			{
				attackToRun();
				_fPlayer.removeEventListener(Event.ENTER_FRAME,onPlayAttack);
				return ;
			}
			if(!_isEnd && ( fromSkin.currentLabel == PlayerActionFlag.NormalAttack 
				|| fromSkin.currentLabel == PlayerActionFlag.MagicAttack ) )
			{
				
				_fPlayer.y = _tPlayer.y - 1;
				onRunning();
				
				if( isCrit() )
				{
					shake( AttackLogic.getInstance().attackScene );
				}
				
				var tPlayer : AttackPlayer;
				for( var i : int = 0; i < _tPlayers.length; i++ )
				{
					tPlayer = _tPlayers[ i ];
//					if( tPlayer.dead == 0 )
//					{
					tPlayer.damage( _damageVos[ i ] );
					
					if( _attackActionVo.beAttactEffectSkin != null && _damageVos[ _cuHitCount ].result != 5 )
					{
						
						var mc : MovieClip = McPool.borrowRes( _attackActionVo.beAttactEffectSkin )
						
						if(_fPlayer.team == 0)
						{
							mc.scaleX	=	1;
						}
						else
						{
							mc.scaleX	=	-1;
						}
						new PointPlayLite(tPlayer.effectPlace,//_attackActionVo.beAttactEffectData["skin"]
							tPlayer[ _attackActionVo.beAttactEffectPos+ "Point" ],
							mc );
					}
//					}
				}
			
				_isEnd	=	true;
				
				_fPlayer.showBuffer( _flowVo.buffer );
				_fPlayer.resetMp( _flowVo.mp );
				
				//发送命中声音
				//ModelLocator.getInstance().dispatchEvent(new SoundEvent(_soundHit));
			}else if( _isEnd && fromSkin.currentLabel == PlayerActionFlag.Wait )
			{
				_fPlayer.removeEventListener(Event.ENTER_FRAME,onPlayAttack);
				
				attackToRun();
			}
		}
		
		protected function isShake():Boolean
		{
			return _attackActionVo.skillAttackType == 5 && isCrit();
		}
		
		protected function isCrit():Boolean
		{
			for each( var damageVo : DamageVo in _damageVos )
			{
				if( damageVo.result == 2 )
				{
					return true;
				}
			}
			return false
		}
	}
}